package com.example.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.api.RedissonReactiveClient;
import org.redisson.api.RedissonRxClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: 临晖
 * @since: 2024-04-18
 */


@Configuration
@Data
@ConfigurationProperties(prefix = "spring.redis")
public class RedissonConfig {




    private String host;

    private String port;

    @Bean
    public RedissonClient redissonClient() {

        String address = String.format("redis://%s:%s", host, port);
        // 1. Create config object
        Config config = new Config();
        config.useSingleServer()
                .setDatabase(3)
                // use "rediss://" for SSL connection
                .setAddress(address);

        // 2. Create Redisson instance

// Sync and Async API
        RedissonClient redisson = Redisson.create(config);

        return redisson;

    }
}
